﻿package mortal.game.view.rebate.openServerSevenDay.panel
{
    import Message.Public.*;
    import com.mui.controls.*;
    import com.mui.display.*;
    import extend.language.*;
    import flash.events.*;
    import flash.utils.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.rebate.data.*;
    import mortal.game.view.rebate.item.*;
    import mortal.game.view.rebate.openServerSevenDay.data.*;
    import mortal.mvc.core.*;

    public class OpenServerSevenDayBottom2 extends GSprite
    {
        protected var _leftBg:GImageBitmap;
        protected var _rightBg:ScaleBitmap;
        protected var _nameBg:GBitmap;
        protected var _items1:CellsGridSprite;
        protected var _items2:CellsGridSprite;
        protected var _items3:CellsGridSprite;
        protected var _items4:CellsGridSprite;
        protected var _line1:ScaleBitmap;
        protected var _line2:ScaleBitmap;
        protected var _line3:ScaleBitmap;
        protected var _order1:GTextFiled;
        protected var _order2:GTextFiled;
        protected var _order3:GTextFiled;
        protected var _order4:GTextFiled;
        protected var _btn1:GLoadingButton;
        protected var _btn2:GLoadingButton;
        protected var _btn3:GLoadingButton;
        protected var _btn4:GLoadingButton;
        protected var _tip1:GTextFiled;
        protected var _tip2:GTextFiled;
        private var _btnArr:Array;
        private var _info2:Object;
        private var _numArr:Array;
        private var _cfgArr:Array;

        public function OpenServerSevenDayBottom2()
        {
            this._btnArr = [];
            this._info2 = {};
            this._numArr = [0, 7, 6, 5, 4];
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._leftBg = UIFactory.gImageBitmap(ImagesConst.OpenServerSevenDayBgNumOne, 0, 0, this);
            this._rightBg = UIFactory.bg(331, -1, 555, 254, this, ImagesConst.PanelBg);
            this._nameBg = UIFactory.gBitmap(ImagesConst.OpenServerSevenDayNumOneBg, 7, 23, this);
            this._items1 = UIFactory.getUICompoment(CellsGridSprite);
            this._items1.colNum = 2;
            this._items1.vCellWid = 73;
            this._items1.hCellWid = 73;
            this._items1.genCellFun = this.genItem;
            this._items1.genCells(4);
            this._items1.x = 156;
            this._items1.y = 62;
            this.addChild(this._items1);
            this._items2 = UIFactory.getUICompoment(CellsGridSprite);
            this._items2.colNum = 3;
            this._items2.vCellWid = 80;
            this._items2.hCellWid = 100;
            this._items2.genCellFun = this.genItem;
            this._items2.genCells(3);
            this._items2.x = 470;
            this._items2.y = 8;
            this.addChild(this._items2);
            this._items3 = UIFactory.getUICompoment(CellsGridSprite);
            this._items3.colNum = 3;
            this._items3.vCellWid = 80;
            this._items3.hCellWid = 73;
            this._items3.genCellFun = this.genItem;
            this._items3.genCells(3);
            this._items3.x = 470;
            this._items3.y = 89;
            this.addChild(this._items3);
            this._items4 = UIFactory.getUICompoment(CellsGridSprite);
            this._items4.colNum = 3;
            this._items4.vCellWid = 80;
            this._items4.hCellWid = 73;
            this._items4.genCellFun = this.genItem;
            this._items4.genCells(3);
            this._items4.x = 470;
            this._items4.y = 172;
            this.addChild(this._items4);
            this._line1 = UIFactory.bg(3, 215, 321, 1, this, ImagesConst.SplitLine4);
            this._line2 = UIFactory.bg(336, 84, 547, 1, this, ImagesConst.SplitLine4);
            this._line3 = UIFactory.bg(335, 166, 548, 1, this, ImagesConst.SplitLine4);
            this._order1 = UIFactory.gTextField("" + Language.getString(71877), 36, 108, 100, 30, this, GlobalStyle.textFormatLv.setSize(15).setBold(true));
            this._order2 = UIFactory.gTextField("" + Language.getString(71878), 358, 35, 100, 20, this, GlobalStyle.textFormatLv.setSize(15).setBold(true));
            this._order3 = UIFactory.gTextField("" + Language.getString(71879), 358, 118, 100, 30, this, GlobalStyle.textFormatLv.setSize(15).setBold(true));
            this._order4 = UIFactory.gTextField("" + Language.getString(71880), 358, 200, 100, 30, this, GlobalStyle.textFormatLv.setSize(15).setBold(true));
            this._btn1 = UIFactory.gLoadingButton(ImagesConst.LineOffCopyCellBtn_upSkin, 37, 152, 80, 25, this);
            this._btn1.label = "" + Language.getString(71881);
            this._btn2 = UIFactory.gLoadingButton(ImagesConst.LineOffCopyCellBtn_upSkin, 739, 35, 80, 26, this);
            this._btn2.label = Language.getString(71881);
            this._btn3 = UIFactory.gLoadingButton(ImagesConst.LineOffCopyCellBtn_upSkin, 739, 116, 80, 26, this);
            this._btn3.label = Language.getString(71881);
            this._btn4 = UIFactory.gLoadingButton(ImagesConst.LineOffCopyCellBtn_upSkin, 739, 198, 80, 25, this);
            this._btn4.label = Language.getString(71881);
            this._tip1 = UIFactory.gTextField("" + Language.getString(71882), 14, 222, 250, 20, this, GlobalStyle.textFormatHuang.setSize(15).setBold(true));
            this._tip2 = UIFactory.gTextField("" + Language.getString(71883), 203, 253, 330, 20, this, GlobalStyle.textFormatPutong.setColor(16777215));
            this._btnArr.push(this._btn1, this._btn2, this._btn3, this._btn4);
            this._btn1.configEventListener(MouseEvent.CLICK, this.onGet);
            this._btn2.configEventListener(MouseEvent.CLICK, this.onGet);
            this._btn3.configEventListener(MouseEvent.CLICK, this.onGet);
            this._btn4.configEventListener(MouseEvent.CLICK, this.onGet);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._leftBg = null;
            this._rightBg = null;
            this._nameBg = null;
            this._items1 = null;
            this._items2 = null;
            this._items3 = null;
            this._items4 = null;
            this._line1 = null;
            this._line2 = null;
            this._line3 = null;
            this._order1 = null;
            this._order2 = null;
            this._order3 = null;
            this._order4 = null;
            this._btn1 = null;
            this._btn2 = null;
            this._btn3 = null;
            this._btn4 = null;
            this._tip1 = null;
            this._tip2 = null;
            this._btnArr = [];
            super.disposeImpl(param1);
            return;
        }// end function

        private function genItem() : RebateItem
        {
            var _loc_1:* = UIFactory.getUICompoment(RebateItem);
            return _loc_1;
        }// end function

        private function onGet(event:MouseEvent) : void
        {
            var _loc_2:* = event.target as GLoadingButton;
            var _loc_3:* = this._btnArr.indexOf(_loc_2);
            if (_loc_3 == -1)
            {
                return;
            }
            if (this._cfgArr == null)
            {
                return;
            }
            var _loc_4:* = this._cfgArr[_loc_3];
            Dispatcher.dispatchEvent(new DataEvent(EventName.RebateOpenServerSevenDayGetReward2, _loc_4.id));
            return;
        }// end function

        public function updateBottomByDayNum2(param1:int) : void
        {
            this._info2.dayNum = param1;
            this.updateRewards2();
            this.updateGetBtn2();
            return;
        }// end function

        public function updateRewards2() : void
        {
            var _loc_5:CellsGridSprite = null;
            var _loc_6:Array = null;
            var _loc_7:int = 0;
            var _loc_8:RebateItem = null;
            var _loc_9:SPlayerItem = null;
            var _loc_1:* = this._info2.dayNum;
            var _loc_2:* = OpenServerSevenDayUtil.getRewardsByDay2(_loc_1);
            if (_loc_2 == null)
            {
                return;
            }
            var _loc_3:* = _loc_2;
            var _loc_4:int = 0;
            while (_loc_4 < _loc_3.length)
            {
                
                _loc_5 = this["_items" + (_loc_4 + 1)] as CellsGridSprite;
                if (_loc_5)
                {
                    _loc_6 = _loc_3[_loc_4];
                    _loc_5.genCells(_loc_6.length);
                    _loc_7 = 0;
                    while (_loc_7 < _loc_6.length)
                    {
                        
                        _loc_8 = _loc_5.cellArr[_loc_7];
                        _loc_9 = _loc_6[_loc_7];
                        if (_loc_8)
                        {
                            _loc_8.updateInfo(_loc_9);
                        }
                        _loc_7++;
                    }
                }
                _loc_4++;
            }
            return;
        }// end function

        public function updateGetBtn2() : void
        {
            var _loc_4:GLoadingButton = null;
            var _loc_6:int = 0;
            var _loc_7:Object = null;
            var _loc_1:* = this._info2.dayNum;
            this._cfgArr = OpenServerSevenDayUtil.getCfgsByDay2(_loc_1);
            if (this._cfgArr == null)
            {
                this.disableAllBtn();
            }
            var _loc_2:* = RebateUtil.getTargetType();
            var _loc_3:* = Cache.instance.openServerSevenDay.dayNumToCfgTargetType[_loc_1];
            var _loc_5:* = Cache.instance.openServerSevenDay.result;
            if (_loc_3 == _loc_2)
            {
                _loc_6 = 0;
                while (_loc_6 < this._cfgArr.length && _loc_6 < this._btnArr.length)
                {
                    
                    _loc_7 = this._cfgArr[_loc_6];
                    _loc_4 = this._btnArr[_loc_6];
                    if (_loc_5[_loc_7.id] == 1)
                    {
                        this.setGetBtn(_loc_4, true);
                    }
                    else if (_loc_5[_loc_7.id] == 2)
                    {
                        this.setGetBtn(_loc_4, false);
                        _loc_4.label = "" + Language.getString(71884);
                    }
                    else
                    {
                        this.setGetBtn(_loc_4, false);
                    }
                    _loc_6++;
                }
            }
            else
            {
                this.disableAllBtn();
            }
            this.updateNames();
            return;
        }// end function

        private function updateNames() : void
        {
            var _loc_2:Object = null;
            var _loc_3:GTextFiled = null;
            var _loc_1:int = 0;
            while (_loc_1 < this._cfgArr.length && _loc_1 < this._btnArr.length)
            {
                
                _loc_2 = this._cfgArr[_loc_1];
                _loc_3 = this["_order" + (_loc_1 + 1)] as GTextFiled;
                if (_loc_3)
                {
                    _loc_3.text = Language.getStringByParam(71885, Cache.instance.openServerSevenDay.nameStrObj[this._info2.dayNum], _loc_2.targetLevel);
                }
                _loc_1++;
            }
            return;
        }// end function

        private function disableAllBtn() : void
        {
            var _loc_2:GLoadingButton = null;
            var _loc_1:int = 0;
            while (_loc_1 < this._btnArr.length)
            {
                
                _loc_2 = this._btnArr[_loc_1];
                this.setGetBtn(_loc_2, false);
                _loc_1++;
            }
            return;
        }// end function

        private function setGetBtn(param1:GLoadingButton, param2:Boolean) : void
        {
            if (param2)
            {
                param1.enabled = true;
                param1.filters = null;
                EffectManager.glowFilterReg(param1);
            }
            else
            {
                EffectManager.glowFilterUnReg(param1);
                param1.enabled = false;
                param1.filters = [FilterConst.colorFilter2];
            }
            return;
        }// end function

    }
}
